package com.yuju.controller.roomTypeStatus;

import com.alibaba.fastjson.JSONObject;
import com.yuju.common.Result;
import com.yuju.enums.ReturnStatusEnum;
import com.yuju.hotel.model.PriceSchemeModel;
import com.yuju.hotel.service.IPriceSchemeService;
import com.yuju.order.enums.RoomTypeStatusReturnCodeEnum;
import com.yuju.roomStatus.model.RoomTypeStatusModel;
import com.yuju.roomStatus.service.IRoomTypeStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 *
 * 类名：RoomTypeStatusController  <br />
 *
 * 功能：微信端房型状态接口
 *
 * @author : jiangp <br />
 * @Date : 2018年1月2日 下午4:01:36  <br />
 * @version : 1.1 <br />
 */
@Controller
@RequestMapping("roomTypeStatus")
public class RoomTypeStatusController {

    @Autowired
    private IRoomTypeStatusService roomTypeStatusService;

    @Autowired
    private IPriceSchemeService priceSchemeService;

    private static String WECHAT_PRICE_SCHEME_NAME = "微信会员";

    /**
     *
     * 功能：获得房型可预订数<br/>
     *
     * @author jiangp
     * @Date 2017年12月13日 上午11:26:03 <br/>
     */
    @RequestMapping("getReserveNum")
    @ResponseBody
    public Result getReserveNum(@RequestBody JSONObject obj) {
        RoomTypeStatusModel roomTypeStatusModel = obj.toJavaObject(RoomTypeStatusModel.class);

        //获得微信会员的价格方案ID
        PriceSchemeModel priceSchemeModel = new PriceSchemeModel();
        priceSchemeModel.setHotelId(roomTypeStatusModel.getHotelId());
        priceSchemeModel.setName(WECHAT_PRICE_SCHEME_NAME);
        PriceSchemeModel wechatPrice = priceSchemeService.find(priceSchemeModel);
        String priceSchemeId = wechatPrice.getId();
        roomTypeStatusModel.setPriceSchemeId(priceSchemeId);
        Result result = new Result();
        List<RoomTypeStatusModel> list
                = roomTypeStatusService.getReserveNum(roomTypeStatusModel);

        if (list != null) {
            result.setRows(list);
            result.setStatus(ReturnStatusEnum.SUCCESS.getCode());
            result.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
            result.setReturnCode(RoomTypeStatusReturnCodeEnum.ROOMTYPESTATUS_RESERVENUM_GET_SUCCESS.getCode());
            result.setReturnMsg(RoomTypeStatusReturnCodeEnum.ROOMTYPESTATUS_RESERVENUM_GET_SUCCESS.getDesc());
        }
        else {
            result.setStatus(ReturnStatusEnum.FAILURE.getCode());
            result.setMsg(ReturnStatusEnum.FAILURE.getDesc());
            result.setReturnCode(RoomTypeStatusReturnCodeEnum.ROOMTYPESTATUS_RESERVENUM_GET_FAILURE.getCode());
            result.setReturnMsg(RoomTypeStatusReturnCodeEnum.ROOMTYPESTATUS_RESERVENUM_GET_FAILURE.getDesc());
        }

        return result;
    }
}
